/*
 * @Description: update main program, able to update the program through IAP after reboot
 （用于更新主程序，运行update()后会自动重启，随后可通过IAP进行主程序烧录）
 * @Author: LI Yihong
 * @Email: liyh@jihua.ac.cn
 * @Date: 2024-09-26 08:53:19
 * @LastEditTime: 2024-10-09 15:43:55
 * @LastEditors: LI Yihong
 * @FilePath: \RT_Stm32F7\applications\update.c
 */
#include <rtthread.h>
#include <finsh.h>
#include "board.h"

void update()
{
    // setting memory value same with IAP program, let IAP to update the program
    uint32_t addr = (uint32_t)(0x20000000);
    *((volatile unsigned char *)(addr + 0)) = 67;
    *((volatile unsigned char *)(addr + 1)) = 56;
    *((volatile unsigned char *)(addr + 2)) = 89;
    *((volatile unsigned char *)(addr + 3)) = 32;
    *((volatile unsigned char *)(addr + 4)) = 50;
    *((volatile unsigned char *)(addr + 5)) = 17;

    rt_kprintf("Updated settings successfully, please wait for automatic reboot.\r\n");

    rt_thread_mdelay(1000);
    rt_hw_cpu_reset(); // reboot
}
MSH_CMD_EXPORT(update, update main program through IAP after reboot);
